package com.ktvme.outTimeBoxState.redis

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.redis.connection.RedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
import org.springframework.data.redis.serializer.RedisSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer

@Configuration
class RedisConfig {
    @Autowired
    private lateinit var redisConnectionFactory: RedisConnectionFactory

//    private val utf8 = Charset.forName("UTF-8")

    @Bean
    fun realTimeDataRedisTemplate(): RedisTemplate<String, Map<String, Any>> {
        val realTimeDataRedisTemplate = RedisTemplate<String, Map<String, Any>>()
        realTimeDataRedisTemplate.setConnectionFactory(redisConnectionFactory)
        realTimeDataRedisTemplate.keySerializer = StringRedisSerializer()
        @Suppress("UNCHECKED_CAST")
        realTimeDataRedisTemplate.valueSerializer = (Jackson2JsonRedisSerializer(Map::class.java) as RedisSerializer<Map<String, Any>>)
        realTimeDataRedisTemplate.afterPropertiesSet()
        return realTimeDataRedisTemplate
    }
}